<template>

</template>

<script>
import {getInfo} from "@/api/login";
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();

export default {
  name: "LoginSso",
  data() {
    return {
      loginRules: {},
      loading: false,
      //验证码开关
      captchaOnOff: true,
      //注册开关
      register: false,
      //重定向
      redirect: undefined
    };
  },
  watch: {

  },
  created() {
    //页面初始化时调单点登录方法
    this.loginSso();
  },
  methods: {
    loginSso(){
      const token = this.$route.query.tokenId;
      console.log("token：",token);
      if(token == '' || token == undefined || token == null){
        this.$message.error("传递的token为空，验证失败!");
      }else{
        this.loading = true;//开启过渡动画
        const loginInfo = {
          "token" : token
        };
        userStore.LoginSso(loginInfo).then(() => {
          this.loading = false;
          //判断当前角色
          getInfo().then((res) => {
            //获取角色名称
            var rolesName = res.roles[0];
            //获取所属场馆
            this.deptInfo = res.dept;
            sessionStorage.setItem("ssUserName", res.user.nickName);
            //处理登录
            this.$router.push({path: this.redirect || "/"}).catch(() => {});
          });
        }).catch(err=> {
          console.log("有异常信息",err);
          this.loading = false;
        });
      }
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">

</style>

